
<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <meta charset="utf-8"></meta>
      <meta name="viewport" content="width=device-width, initial-scale=1.0"></meta>
      <title>10.3.&nbsp;Collection Functions - Chapter&nbsp;10.&nbsp;Utility Functions</title>
      <link rel="stylesheet" type="text/css" href="../../docbook.css"></link>
      <link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans:400,300,400italic,600,300italic"></link>
      <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/codemirror.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/theme/neo.min.css"></link>
      <link rel="stylesheet" type="text/css" href="../../css/chunked-base.css"></link>
      <link rel="stylesheet" type="text/css" href="../../css/extra.css"></link><script src="//code.jquery.com/jquery-1.12.4.js" type="text/javascript"></script><script src="//cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js" type="text/javascript"></script><script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" type="text/javascript"></script><script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/codemirror.min.js" type="text/javascript"></script><script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/addon/runmode/runmode.min.js" type="text/javascript"></script><script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/mode/cypher/cypher.min.js" type="text/javascript"></script><script src="../../javascript/datatable.js" type="text/javascript"></script><script src="../../javascript/colorize.js" type="text/javascript"></script><script src="../../javascript/tabs-for-chunked.js" type="text/javascript"></script><script src="../../javascript/mp-nav.js" type="text/javascript"></script><script src="../../javascript/versionswitcher.js" type="text/javascript"></script><script src="../../javascript/version.js" type="text/javascript"></script><script src="//s3-eu-west-1.amazonaws.com/alpha.neohq.net/docs/new-manual/assets/search.js" type="text/javascript"></script><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"></meta>
      <link rel="prev" href="../map-functions/" title="10.2.&nbsp;Map Functions"></link>
      <link rel="next" href="../text-functions/" title="10.4.&nbsp;Text Functions"></link>
      <link rel="shortcut icon" href="https://neo4j.com/wp-content/themes/neo4jweb/favicon.ico"></link><script>
        $(document).ready(function() {
          CodeMirror.colorize();
          tabTheSource($('body'));
          var $header = $('header').first();
          $header.prepend(
            $('<a href="" id="logo"><img src="https://neo4j.com/wp-content/themes/neo4jweb/assets/images/neo4j-logo-2015.png" alt="Neo4j Logo"></img></a>')
          );
          var $sidebar = $('<div id="sidebar-wrapper"></div>');
          $.get('toc.html', function (d){
            $(d).appendTo($sidebar);
            highlightToc();
            highlightLibraryHeader();
          });
          $sidebar.insertAfter($('header').first());
        });
        </script></head>
   <body>
      <header>
         <div class="searchbox">
            <form id="search-form" class="search" name="search-form" role="search"><input id="search-form-input" name="q" title="search" type="search" lang="en" placeholder="Search Neo4j docs..." aria-label="Search Neo4j documentation" max-length="128" required="required"></input><input id="search-form-button" type="submit" value="Search"></input></form>
         </div>
         <ul class="documentation-library">
            <li><a href="https://neo4j.com/docs/operations-manual/current">Operations Manual</a></li>
            <li><a href="https://neo4j.com/docs/developer-manual/current/">Developer Manual</a></li>
            <li><a href="https://neo4j.com/docs/ogm-manual/current/">OGM Manual</a></li>
            <li><a href="https://neo4j.com/docs/graph-algorithms/current/">Graph Algorithms</a></li>
            <li><a href="https://neo4j-contrib.github.io/neo4j-apoc-procedures/3.4/">APOC</a></li>
            <li><a href="https://neo4j.com/docs/java-reference/current/">Java Reference</a></li>
         </ul>
         <nav id="header-nav"><span class="nav-previous"><a accesskey="p" href="../map-functions/"><span class="fa fa-long-arrow-left" aria-hidden="true"></span>Map Functions</a></span><span class="nav-current">
               <p class="nav-title hidden">10.3.&nbsp;Collection Functions</p></span><span class="nav-next"><a accesskey="n" href="../text-functions/">Text Functions<span class="fa fa-long-arrow-right" aria-hidden="true"></span></a></span></nav>
      </header>
      <div id="search-results" class="hidden"></div>
      <section class="section" id="collection-list-functions">
         <div class="titlepage">
            <div>
               <div>
                  <h2 class="title" style="clear: both"><a class="anchor" href="#collection-list-functions"></a>10.3.&nbsp;Collection Functions
                  </h2>
               </div>
            </div>
         </div>
         <p>APOC has a wide variety of Collection and List functions.</p>
         <div class="informaltable">
            <div class="table" id="d0e11126">
               <table class="informaltable" border="1">
                  <colgroup>
                     <col class="col_1"></col>
                     <col class="col_2"></col>
                  </colgroup>
                  <tbody>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.sum([0.5,1,2.3])</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>sum of all values in a list</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.avg([0.5,1,2.3])</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>avg of all values in a list</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.min([0.5,1,2.3])</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>minimum of all values in a list</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.max([0.5,1,2.3])</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>maximum of all values in a list</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.sumLongs([1,3,3])</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>sums all numeric values in a list</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.partition(list,batchSize)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>partitions a list into sublists of <code class="literal">batchSize</code></p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.zip([list1],[list2])</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>all values in a list</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.pairs([1,2,3]) YIELD value</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>[1,2],[2,3],[3,null]</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.pairsMin([1,2,3]) YIELD value</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>[1,2],[2,3]</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.toSet([list])</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>returns a unique list backed by a set</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.sort(coll)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>sort on Collections</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.sortNodes([nodes], 'name')</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>sort nodes by property, ascending sorting by adding ^ in front of the sorting field</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.sortMaps([maps], 'key')</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>sort maps by map key, ascending sorting by adding ^ in front of the sorting field</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.reverse(coll)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>returns the reversed list</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.contains(coll, value)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>returns true if collection contains the value</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.containsAll(coll, values)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>optimized contains-all operation (using a HashSet) returns true or false</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.containsSorted(coll, value)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>optimized contains on a sorted list operation (Collections.binarySearch) (returns true or false)</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.containsAllSorted(coll, value)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>optimized contains-all on a sorted list operation (Collections.binarySearch) (returns true or false)</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.union(first, second)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>creates the distinct union of the 2 lists</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.subtract(first, second)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>returns unique set of first list with all elements of second list removed</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.removeAll(first, second)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>returns first list with all elements of second list removed</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.intersection(first, second)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>returns the unique intersection of the two lists</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.disjunction(first, second)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>returns the disjunct set of the two lists</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.unionAll(first, second)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>creates the full union with duplicates of the two lists</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.split(list,value)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>splits collection on given values rows of lists, value itself will not be part of resulting lists</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.indexOf(coll, value)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>position of value in the list</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.shuffle(coll)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>returns the shuffled list</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.randomItem(coll)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>returns a random item from the list</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.randomItems(coll, itemCount, allowRepick: false)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>returns a list of <code class="literal">itemCount</code> random items from the list, optionally allowing picked elements to be picked again
                           </p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.containsDuplicates(coll)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>returns true if a collection contains duplicate elements</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.duplicates(coll)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>returns a list of duplicate items in the collection</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.duplicatesWithCount(coll)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>returns a list of duplicate items in the collection and their count, keyed by <code class="literal">item</code> and <code class="literal">count</code> (e.g., <code class="literal">[{item: xyz, count:2}, {item:zyx, count:5}]</code>)
                           </p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.occurrences(coll, item)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>returns the count of the given item in the collection</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.frequencies(coll)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>returns a list of frequencies of the items in the collection, keyed by <code class="literal">item</code> and <code class="literal">count</code> (e.g., <code class="literal">[{item: xyz, count:2}, {item:zyx, count:5}, {item:abc, count:1}]</code>)
                           </p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.frequenciesAsMap(coll)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>return a map of frequencies of the items in the collection, keyed by <code class="literal">item</code> and <code class="literal">count</code> (e.g., <code class="literal">{1: 2, 3: 2}</code>)
                           </p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.sortMulti</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>sort list of maps by several sort fields (ascending with ^ prefix) and optionally applies limit and skip</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.flatten</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>flattens a nested list</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.combinations(coll, minSelect, maxSelect:minSelect)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>Returns collection of all combinations of list elements of selection size between minSelect and maxSelect (default:minSelect),
                              inclusive
                           </p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">CALL apoc.coll.elements(list,limit,offset) yield _1,_2,..,_10,_1s,_2i,_3f,_4m,_5l,_6n,_7r,_8p</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>deconstruct subset of mixed list into identifiers of the correct type</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.set(coll, index, value)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>set index to value</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.insert(coll, index, value)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>insert value at index</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.insertAll(coll, index, values)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>insert values at index</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.remove(coll, index, [length=1])</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>remove range of values from index to length</p>
                        </td>
                     </tr>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.coll.different(values)</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>returns true if value are different</p>
                        </td>
                     </tr>
                  </tbody>
               </table>
            </div>
         </div>
      </section>
      <footer><script type="text/javascript">
          (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
          })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
          //Allow Linker
          ga('create', 'UA-1192232-34','auto', {'allowLinker': true});
          ga('send', 'pageview');
          // Load the plugin.
          ga('require', 'linker');
          // Define which domains to autoLink.
          ga('linker:autoLink', ['neo4j.org','neo4j.com','neotechnology.com','graphdatabases.com','graphconnect.com']);
        </script><script type="text/javascript">
          document.write(unescape("%3Cscript src='//munchkin.marketo.net/munchkin.js' type='text/javascript'%3E%3C/script%3E"));
        </script><script>Munchkin.init('773-GON-065');</script></footer>
   </body>
</html>